package com.zhenhao.xsq.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class TimeAxisView extends View {

    private Paint axisPaint;
    private Paint textPaint;

    public TimeAxisView(Context context) {
        super(context);
        init();
    }

    public TimeAxisView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        axisPaint = new Paint();
        axisPaint.setColor(Color.GRAY);
        axisPaint.setStyle(Paint.Style.STROKE);

        textPaint = new Paint();
        textPaint.setColor(Color.BLACK);
        textPaint.setTextSize(16);
        textPaint.setTextAlign(Paint.Align.CENTER);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // 绘制时间轴
        canvas.drawLine(0, getHeight() / 2f, getWidth(), getHeight() / 2f, axisPaint);

        // 绘制时间刻度
        int totalHours = 24; // 假设一天有24小时
        float hourWidth = getWidth() / totalHours;
        for (int i = 0; i < totalHours; i++) {
            float x = i * hourWidth;
            canvas.drawLine(x, getHeight() / 2f - 20, x, getHeight() / 2f + 20, axisPaint);
            canvas.drawText(String.format("%d:00", i), x, getHeight() / 2f + 50, textPaint);
        }
    }
}
